﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using BLL.Security;
using BLL.Services.Responses;
using Web.Infrastructure.Models;

namespace Web.Models.Responses
{
    public class ResponseModel: BaseModel 
    {
        [Required]
        public string Content { get; set; }

        [Required]
        public int BookId { get; set; }

        public static explicit operator Response(ResponseModel model)
        {
            return new Response
                {
                    BookId = model.BookId,
                    Content = model.Content,
                    DateOfPublish = DateTime.Now,
                    UserId = EnvironmentContext.User.UserId
                };
        }

        public static IEnvironmentContext EnvironmentContext
        {
            get { return DependencyResolver.Current.GetService<IEnvironmentContext>(); }
        }
    }
}